﻿using PlainElastic.Net;
using PlainElastic.Net.Serialization;
using PlainElasticSample.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlainElasticSample
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                PlainElasticTest();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }

        private static void PlainElasticTest()
        {
            var person = new Person("gainorloss");
            var myConn = new ElasticConnection("localhost", 9200);
            var serializer = new JsonNetSerializer();
            var indexCommand = new IndexCommand("verticalsite", "person", person.Id);
            var operationRet = myConn.Put(indexCommand, serializer.Serialize(person));
            var indexRet = serializer.ToIndexResult(operationRet);
            if (indexRet.created)
            {
                Console.WriteLine("Success!");
            }
            else
            {
                Console.WriteLine(indexRet.error);
            }
        }
    }
}
